#pragma once
#include "vn/String.hpp"
#include <locale.h>

// if source code is saved as UTF-8 without BOM, L"cộng" will be L"Ä‘Æ°á»ng"

void StringTestUnicode() {_test_func_;
	{
		_block_("ansi to and from unicode");
		StringW w = StringA("Con duong");
		assert(w == "Con duong");
		StringA a = StringW(L"Bột ngọt");
		assert(a != StringW(L"Bột ngọt"));
		assert(a == StringA(L"Bột ngọt"));

		w = "duong con";
		assert(w == "duong con");
		w = L"duong sua bot ngot";
		assert(w == L"duong sua bot ngot");

		a = "duong con";
		assert(a == "duong con");
		a = String(L"duong sua bot ngot");
		assert(a == L"duong sua bot ngot");
	}

	{
		_block_("1");
		String a;
		assert(a == (LPChar)0);
		
		String b((LPChar)0);
		assert(b == (LPChar)0);
		
		String c("cong hoa xa hoi");
		assert(c == "cong hoa xa hoi");
		
		String d(L"Cong hoa xa hoi");
		// String d(L"Cong hoa xa hoi");
		// if ansi, we cannot assert(d == "Cong hoa xa hoi");
		assert(d == (String)L"Cong hoa xa hoi");
		assert(d.GetLength() == 15);

		String e1((LPChar)0, 4);
		assert(e1 == (LPChar)0);
		String e2((LPChar)0, -1);
		assert(e2 == (LPChar)0);
		String e3((LPChar)0, 0);
		assert(e3 == (LPChar)0);
		//String e4("a", -1);
		//assert(e4 == (LPChar)0);
		String e5("", 0);
		assert(e5 == "");
		// temp remove: this test is right with BOM, (utf8 have BOM)
		// String f(L"Cong hoa xa hoi", 4);
		// assert(f == String(L"Cộng"));
		// assert(f.GetLength() == 4);
	}

	{
		_block_("2");
		String a;
		String aa(a);
		assert(aa == (LPCChar)0);

		String b("");
		String bb(b);
		assert(bb == "");

		const String c("cong hoa xa hoi");
		String cc(c);
		assert(cc == "cong hoa xa hoi");
	}

	{
		_block_("3");
		const String a("chuoi");		
		const TChar *pa = a.C_STR();

		String b("chuoi");
		TChar *pb= b.C_STR();
	}

	{
		_block_("4");
		String a = "123";
		a[0] = 'a';
		a[1] = 'b';
		a[2] = 'c';
		assert(a == "abc");

		const String b = "123";
		b[0];
		b[1];
		b[2];
		assert(b == "123");
	}

	{
		_block_("5");
		String a;
		String b = "1234";
		a = "";
		assert(a == "");
		a = "1";
		assert(a == "1");
		a = "1------------------2";
		assert(a == "1------------------2");
		b = "";
		assert(b == "");
	}

	{_block_("6");
		const String nullS;
		const String notnullS = "1234";

		String d1, d2;

		d1 = nullS;
		d2 = notnullS;

		d2 = nullS;	// re-assign
	}

	// self assign
	{_block_("7");
		String a;
		String b = "1234";
		a = a;
//		assert(a == (LPChar)0);
		b = b;
		assert(b == "1234");
	}


	{_block_("8");
		String a;
		a+=(LPChar)0;
		a+=a;
		a+="1 ";
		a+=a;
		a+="end";

		assert(a == "1 1 end");
	}

	{_block_("9");
		String a;
		a.Substring(0, 0);
		a.Substring(0, 0);
		a = "12345";

		assert(a.Substring(0, 0) == "");
		assert(a.Substring(0, 1) == "1");
		assert(a.Substring(2, 3) == "345");
		assert(a.Substring(0, 5) == "12345");
		assert(a.Substring(4, a.GetLength() - 4) == "5");
	}

	{_block_("10");
		const String a;
		const String b("12345");

		assert(a.GetLength() == 0);
		assert(b.GetLength() == 5);
	}

	// compare String == String
	{_block_("10");
		const String a;
		const String b("12345");

		assert(a==a);
		assert(b==b);

		assert(a!=b);
		assert(b!=a);

		String c("12345");
		assert(b == c);
	}

	// compare String == psz
	{_block_("11");
		const String a;
		const String b("12345");

		assert(a == (LPChar)0);
		assert(b == "12345");
	}

	// ToLower, ToUpper
	{

		const String a;
		const String b(L"cong HOA");
		
		//assert(b.ToUpper() == L"CONG HOA");
		//assert(b.ToLower() == L"cong hoa");
	}


	// "abc" == String("abc")
	{
	}

	// MFC
	{

	}



	// empty
	{

	}


}


void StringTest() {_test_func_;
{
	_block_("ansi to and from unicode");
	StringW w = StringA("Con duong");
	assert(w == "Con duong");
	StringA a = StringW(L"Bột ngọt");
	assert(a != StringW(L"Bột ngọt"));
	assert(a == StringA(L"Bột ngọt"));

	w = "duong con";
	assert(w == "duong con");
	w = L"duong sua bot ngot";
	assert(w == L"duong sua bot ngot");

	a = "duong con";
	assert(a == "duong con");
	// temp remove: this test is right with BOM, (utf8 have BOM)
	// a = String(L"duong sua bot ngot");
	// assert(a == L"???ng s?a b?t ng?t");
}

{
	_block_("1");
	String a;
	assert(a == (LPChar)0);

	String b((LPChar)0);
	assert(b == (LPChar)0);

	String c("cong hoa xa hoi");
	assert(c == "cong hoa xa hoi");

	String d(L"Cong hoa xa hoi");
	// String d(L"Cong hoa xa hoi");
	// if ansi, we cannot assert(d == "Cong hoa xa hoi");
	assert(d == (String)L"Cong hoa xa hoi");
	assert(d.GetLength() == 15);

	String e1((LPChar)0, 4);
	assert(e1 == (LPChar)0);
	String e2((LPChar)0, -1);
	assert(e2 == (LPChar)0);
	String e3((LPChar)0, 0);
	assert(e3 == (LPChar)0);
	//String e4("a", -1);
	//assert(e4 == (LPChar)0);
	String e5("", 0);
	assert(e5 == "");
	// temp remove: this test is right with BOM, (utf8 have BOM)
	// String f(L"Cong hoa xa hoi", 4);
	// assert(f == String(L"Cộng"));
	// assert(f.GetLength() == 4);
}

{
	_block_("2");
	String a;
	String aa(a);
	assert(aa == (LPCChar)0);

	String b("");
	String bb(b);
	assert(bb == "");

	const String c("cong hoa xa hoi");
	String cc(c);
	assert(cc == "cong hoa xa hoi");
}

{
	_block_("3");
	const String a("chuoi");		
	const TChar *pa = a.C_STR();

	String b("chuoi");
	TChar *pb= b.C_STR();
}

{
	_block_("4");
	String a = "123";
	a[0] = 'a';
	a[1] = 'b';
	a[2] = 'c';
	assert(a == "abc");

	const String b = "123";
	b[0];
	b[1];
	b[2];
	assert(b == "123");
}

{
	_block_("5");
	String a;
	String b = "1234";
	a = "";
	assert(a == "");
	a = "1";
	assert(a == "1");
	a = "1------------------2";
	assert(a == "1------------------2");
	b = "";
	assert(b == "");
}

{
	_block_("6");
	const String nullS;
	const String notnullS = "1234";

	String d1, d2;

	d1 = nullS;
	d2 = notnullS;

	d2 = nullS;	// re-assign
}

// self assign
{
	_block_("7");
	String a;
	String b = "1234";
	a = a;
	//		assert(a == (LPChar)0);
	b = b;
	assert(b == "1234");
}


{
	_block_("8");
	String a;
	a+=(LPChar)0;
	a+=a;
	a+="1 ";
	a+=a;
	a+="end";

	assert(a == "1 1 end");
}

{
	_block_("9");
	String a;
	a.Substring(0, 0);
	a.Substring(0, 0);
	a = "12345";

	assert(a.Substring(0, 0) == "");
	assert(a.Substring(0, 1) == "1");
	assert(a.Substring(2, 3) == "345");
	assert(a.Substring(0, 5) == "12345");
	assert(a.Substring(4, a.GetLength() - 4) == "5");
}

{
	_block_("10");
	const String a;
	const String b("12345");

	assert(a.GetLength() == 0);
	assert(b.GetLength() == 5);
}

// compare String == String
{
	_block_("10");
	const String a;
	const String b("12345");

	assert(a==a);
	assert(b==b);

	assert(a!=b);
	assert(b!=a);

	String c("12345");
	assert(b == c);
}

// compare String == psz
{
	_block_("11");
	const String a;
	const String b("12345");

	assert(a == (LPChar)0);
	assert(b == "12345");
}

// ToLower, ToUpper
{

	const String a;
	const String b(L"cong HOA");

	//assert(b.ToUpper() == L"CONG HOA");
	//assert(b.ToLower() == L"cong hoa");
}


// "abc" == String("abc")
{
}

// MFC
{

}



// empty
{

}


}
